package org.hhgzs.modules.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hhgzs.modules.erp.constants.BusinessConstants;
import org.hhgzs.modules.erp.entity.Supplier;
import org.hhgzs.modules.erp.mapper.SupplierMapper;
import org.hhgzs.modules.erp.service.SupplierService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 供应商/客户信息表 服务实现类
 * </p>
 *
 * @author peiqy
 * @since 2021-07-14
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {
    private final  SupplierMapper supplierMapper;
    @Override
    public List<Supplier> findBySelectSup() {
        QueryWrapper<Supplier> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Supplier::getType,"供应商");
        queryWrapper.lambda().eq(Supplier::getEnabled,true);
        queryWrapper.lambda().ne(Supplier::getDeleteFlag, BusinessConstants.DELETE_FLAG_DELETED);
        queryWrapper.lambda().orderBy(true,true,Supplier::getId);
        return supplierMapper.selectList(queryWrapper);

    }

    @Override
    public List<Supplier> findBySelectRetail() {
        QueryWrapper<Supplier> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Supplier::getType,"会员");
        queryWrapper.lambda().eq(Supplier::getEnabled,true);
        queryWrapper.lambda().ne(Supplier::getDeleteFlag, BusinessConstants.DELETE_FLAG_DELETED);
        queryWrapper.lambda().orderBy(true,true,Supplier::getId);
        return supplierMapper.selectList(queryWrapper);
    }

    @Override
    public List<Supplier> findBySelectCus() {
        QueryWrapper<Supplier> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Supplier::getType,"客户");
        queryWrapper.lambda().eq(Supplier::getEnabled,true);
        queryWrapper.lambda().ne(Supplier::getDeleteFlag, BusinessConstants.DELETE_FLAG_DELETED);
        queryWrapper.lambda().orderBy(true,true,Supplier::getId);
        return supplierMapper.selectList(queryWrapper);
    }
}
